<?php
require '../common.php';



$tags = getAll("select * from tag");

$str = $_SERVER['HTTP_REFERER'];
$arr = explode("/",$str);
$flag = $arr[count($arr)-1];

if("add.php"==$flag){
    if ($_POST ) {

        $tag_id = $_POST["tagId"];
        $name = $_POST["name"];

        $content = $_POST["content"];

        $time = time();
        query("insert into article (name,content,time,tag_id) values('$name','$content','$time','$tag_id')");
        redirect("article.php", "添加成功！");
    }
}elseif ("add_tag.html"==$flag){
    if($_POST) {
        $tagName = $_POST["name"];
        query("insert into tag (name) values('$tagName')");
        redirect("tag.php", "添加成功！");
    }
}
    $smarty->assign("tags",$tags);
    $smarty->display("add.html");
  //  require 'templates/add.html';

?>